/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;


import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import model.Imovel;
import org.primefaces.model.SelectableDataModel;


/**
 *
 * @author Elizangela
 */

public class ImovelDataModel extends ListDataModel<Imovel> implements SelectableDataModel<Imovel>,Serializable {
    
    public ImovelDataModel() {  
    }  
  
    public ImovelDataModel(List<Imovel> data) {  
        super(data);  
    }  
      
    @Override  
    public Imovel getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<Imovel> imoveis = (List<Imovel>)this. getWrappedData();  
          
        for(Imovel imovel : imoveis) {  
            String id = ""+imovel.getCodImovel();  
            if(id.equals(rowKey))  
                return imovel;  
        }  
          
        return null;  
    }  
    
     @Override  
    public Object getRowKey(Imovel obj) {  
        return ""+obj.getCodImovel();  
    }  
  
    
}  